<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Standard Macros</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
<link rel="start" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="prev" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types">
<link rel="next" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros">
<meta name="generator" content="GTK-Doc V1.9 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="glib.html" title="GLib Overview">
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
<link rel="chapter" href="tools.html" title="GLib Tools">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
<link rel="index" href="ix09.html" title="Index of new symbols in 2.14">
<link rel="index" href="ix10.html" title="Index of new symbols in 2.16">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Limits-of-Basic-Types.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-fundamentals.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-Type-Conversion-Macros.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2886423" class="shortcut">Top</a>
                  &#160;|&#160;
                  <a href="#id2886605" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="glib-Standard-Macros"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id2886423"></a><span class="refentrytitle">Standard Macros</span>
</h2>
<p>Standard Macros &#8212; commonly-used macros.</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">

#include &lt;glib.h&gt;



#define             <a class="link" href="glib-Standard-Macros.html#G-OS-WIN32:CAPS">G_OS_WIN32</a>
#define             <a class="link" href="glib-Standard-Macros.html#G-OS-BEOS:CAPS">G_OS_BEOS</a>
#define             <a class="link" href="glib-Standard-Macros.html#G-OS-UNIX:CAPS">G_OS_UNIX</a>

#define             <a class="link" href="glib-Standard-Macros.html#G-DIR-SEPARATOR:CAPS">G_DIR_SEPARATOR</a>
#define             <a class="link" href="glib-Standard-Macros.html#G-DIR-SEPARATOR-S:CAPS">G_DIR_SEPARATOR_S</a>
#define             <a class="link" href="glib-Standard-Macros.html#G-IS-DIR-SEPARATOR:CAPS">G_IS_DIR_SEPARATOR</a>                  (c)
#define             <a class="link" href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR:CAPS">G_SEARCHPATH_SEPARATOR</a>
#define             <a class="link" href="glib-Standard-Macros.html#G-SEARCHPATH-SEPARATOR-S:CAPS">G_SEARCHPATH_SEPARATOR_S</a>

#define             <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS">TRUE</a>
#define             <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS">FALSE</a>

#define             <a class="link" href="glib-Standard-Macros.html#NULL:CAPS">NULL</a>

#define             <a class="link" href="glib-Standard-Macros.html#MIN:CAPS">MIN</a>                                 (a, b)
#define             <a class="link" href="glib-Standard-Macros.html#MAX:CAPS">MAX</a>                                 (a, b)

#define             <a class="link" href="glib-Standard-Macros.html#ABS:CAPS">ABS</a>                                 (a)
#define             <a class="link" href="glib-Standard-Macros.html#CLAMP:CAPS">CLAMP</a>                               (x, low, high)

#define             <a class="link" href="glib-Standard-Macros.html#G-STRUCT-MEMBER:CAPS">G_STRUCT_MEMBER</a>                     (member_type, struct_p, struct_offset)
#define             <a class="link" href="glib-Standard-Macros.html#G-STRUCT-MEMBER-P:CAPS">G_STRUCT_MEMBER_P</a>                   (struct_p, struct_offset)
#define             <a class="link" href="glib-Standard-Macros.html#G-STRUCT-OFFSET:CAPS">G_STRUCT_OFFSET</a>                     (struct_type, member)

#define             <a class="link" href="glib-Standard-Macros.html#G-MEM-ALIGN:CAPS">G_MEM_ALIGN</a>

#define             <a class="link" href="glib-Standard-Macros.html#G-CONST-RETURN:CAPS">G_CONST_RETURN</a>
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id2886605"></a><h2>Description</h2>
<p>
These macros provide a few commonly-used features.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id2886620"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id2886631"></a><h3>
<a name="G-OS-WIN32:CAPS"></a>G_OS_WIN32</h3>
<a class="indexterm" name="id2886643"></a><pre class="programlisting">#define G_OS_WIN32
</pre>
<p>
This macro is defined only on Windows. So you can bracket
Windows-specific code in "#ifdef G_OS_WIN32".
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886666"></a><h3>
<a name="G-OS-BEOS:CAPS"></a>G_OS_BEOS</h3>
<a class="indexterm" name="id2886673"></a><pre class="programlisting">#define G_OS_BEOS
</pre>
<p>
This macro is defined only on BeOS. So you can bracket
BeOS-specific code in "#ifdef G_OS_BEOS".
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886686"></a><h3>
<a name="G-OS-UNIX:CAPS"></a>G_OS_UNIX</h3>
<a class="indexterm" name="id2886702"></a><pre class="programlisting">#define G_OS_UNIX
</pre>
<p>
This macro is defined only on UNIX. So you can bracket
UNIX-specific code in "#ifdef G_OS_UNIX".
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886719"></a><h3>
<a name="G-DIR-SEPARATOR:CAPS"></a>G_DIR_SEPARATOR</h3>
<a class="indexterm" name="id2886735"></a><pre class="programlisting">#define             G_DIR_SEPARATOR</pre>
<p>
The directory separator character.
This is '/' on UNIX machines and '\' under Windows.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886752"></a><h3>
<a name="G-DIR-SEPARATOR-S:CAPS"></a>G_DIR_SEPARATOR_S</h3>
<a class="indexterm" name="id2886764"></a><pre class="programlisting">#define             G_DIR_SEPARATOR_S</pre>
<p>
The directory separator as a string.
This is "/" on UNIX machines and "\" under Windows.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886781"></a><h3>
<a name="G-IS-DIR-SEPARATOR:CAPS"></a>G_IS_DIR_SEPARATOR()</h3>
<a class="indexterm" name="id2886795"></a><pre class="programlisting">#define             G_IS_DIR_SEPARATOR(c)</pre>
<p>
Checks whether a character is a directory 
separator. It returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for '/' on UNIX
machines and for '\' or '/' under Windows.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>c</code></em>&#160;:</span></p></td>
<td>a character
</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.6


</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886848"></a><h3>
<a name="G-SEARCHPATH-SEPARATOR:CAPS"></a>G_SEARCHPATH_SEPARATOR</h3>
<a class="indexterm" name="id2886861"></a><pre class="programlisting">#define             G_SEARCHPATH_SEPARATOR</pre>
<p>
The search path separator character.
This is ':' on UNIX machines and ';' under Windows.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886878"></a><h3>
<a name="G-SEARCHPATH-SEPARATOR-S:CAPS"></a>G_SEARCHPATH_SEPARATOR_S</h3>
<a class="indexterm" name="id2886892"></a><pre class="programlisting">#define             G_SEARCHPATH_SEPARATOR_S</pre>
<p>
The search path separator as a string.
This is ":" on UNIX machines and ";" under Windows.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886909"></a><h3>
<a name="TRUE:CAPS"></a>TRUE</h3>
<a class="indexterm" name="id2886921"></a><pre class="programlisting">#define	TRUE	(!FALSE)
</pre>
<p>
Defines the <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> value for the <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> type.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2886955"></a><h3>
<a name="FALSE:CAPS"></a>FALSE</h3>
<a class="indexterm" name="id2886967"></a><pre class="programlisting">#define	FALSE	(0)
</pre>
<p>
Defines the <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> value for the <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> type.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887001"></a><h3>
<a name="NULL:CAPS"></a>NULL</h3>
<a class="indexterm" name="id2887013"></a><pre class="programlisting">#define             NULL</pre>
<p>
Defines the standard <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> pointer.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887039"></a><h3>
<a name="MIN:CAPS"></a>MIN()</h3>
<a class="indexterm" name="id2887052"></a><pre class="programlisting">#define MIN(a, b)  (((a) &lt; (b)) ? (a) : (b))
</pre>
<p>
Calculates the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>a</code></em>&#160;:</span></p></td>
<td>a numeric value.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>b</code></em>&#160;:</span></p></td>
<td>a numeric value.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the minimum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887132"></a><h3>
<a name="MAX:CAPS"></a>MAX()</h3>
<a class="indexterm" name="id2887144"></a><pre class="programlisting">#define MAX(a, b)  (((a) &gt; (b)) ? (a) : (b))
</pre>
<p>
Calculates the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>a</code></em>&#160;:</span></p></td>
<td>a numeric value.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>b</code></em>&#160;:</span></p></td>
<td>a numeric value.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the maximum of <em class="parameter"><code>a</code></em> and <em class="parameter"><code>b</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887225"></a><h3>
<a name="ABS:CAPS"></a>ABS()</h3>
<a class="indexterm" name="id2887237"></a><pre class="programlisting">#define ABS(a)	   (((a) &lt; 0) ? -(a) : (a))
</pre>
<p>
Calculates the absolute value of <em class="parameter"><code>a</code></em>.
The absolute value is simply the number with any negative sign taken away.
</p>
<p>
For example,
</p>
<div class="itemizedlist"><ul type="disc">
<li><p>
ABS(-10) is 10.
</p></li>
<li><p>
ABS(10) is also 10.
</p></li>
</ul></div>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>a</code></em>&#160;:</span></p></td>
<td>a numeric value.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the absolute value of <em class="parameter"><code>a</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887310"></a><h3>
<a name="CLAMP:CAPS"></a>CLAMP()</h3>
<a class="indexterm" name="id2887322"></a><pre class="programlisting">#define CLAMP(x, low, high)  (((x) &gt; (high)) ? (high) : (((x) &lt; (low)) ? (low) : (x)))
</pre>
<p>
Ensures that <em class="parameter"><code>x</code></em> is between the limits set by <em class="parameter"><code>low</code></em> and <em class="parameter"><code>high</code></em>. If <em class="parameter"><code>low</code></em> is
greater than <em class="parameter"><code>high</code></em> the result is undefined.
</p>
<p>
For example,
</p>
<div class="itemizedlist"><ul type="disc">
<li><p>
CLAMP(5, 10, 15) is 10.
</p></li>
<li><p>
CLAMP(15, 5, 10) is 10.
</p></li>
<li><p>
CLAMP(20, 15, 25) is 20.
</p></li>
</ul></div>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>x</code></em>&#160;:</span></p></td>
<td>the value to clamp.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>low</code></em>&#160;:</span></p></td>
<td>the minimum value allowed.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>high</code></em>&#160;:</span></p></td>
<td>the maximum value allowed.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the value of <em class="parameter"><code>x</code></em> clamped to the range between <em class="parameter"><code>low</code></em> and <em class="parameter"><code>high</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887466"></a><h3>
<a name="G-STRUCT-MEMBER:CAPS"></a>G_STRUCT_MEMBER()</h3>
<a class="indexterm" name="id2887479"></a><pre class="programlisting">#define             G_STRUCT_MEMBER(member_type, struct_p, struct_offset)</pre>
<p>
Returns a member of a structure at a given offset, using the given type.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>member_type</code></em>&#160;:</span></p></td>
<td>the type of the struct field.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>struct_p</code></em>&#160;:</span></p></td>
<td>a pointer to a struct.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>struct_offset</code></em>&#160;:</span></p></td>
<td>the offset of the field from the start of the struct, in bytes.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the struct member.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887554"></a><h3>
<a name="G-STRUCT-MEMBER-P:CAPS"></a>G_STRUCT_MEMBER_P()</h3>
<a class="indexterm" name="id2887567"></a><pre class="programlisting">#define             G_STRUCT_MEMBER_P(struct_p, struct_offset)</pre>
<p>
Returns an untyped pointer to a given offset of a struct.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>struct_p</code></em>&#160;:</span></p></td>
<td>a pointer to a struct.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>struct_offset</code></em>&#160;:</span></p></td>
<td>the offset from the start of the struct, in bytes.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>an untyped pointer to <em class="parameter"><code>struct_p</code></em> plus <em class="parameter"><code>struct_offset</code></em> bytes.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887639"></a><h3>
<a name="G-STRUCT-OFFSET:CAPS"></a>G_STRUCT_OFFSET()</h3>
<a class="indexterm" name="id2887652"></a><pre class="programlisting">#define             G_STRUCT_OFFSET(struct_type, member)</pre>
<p>
Returns the offset, in bytes, of a member of a struct.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>struct_type</code></em>&#160;:</span></p></td>
<td>a structure type, e.g. <span class="structname">GtkWidget</span>.
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>member</code></em>&#160;:</span></p></td>
<td>a field in the structure, e.g. <em class="structfield"><code>window</code></em>.
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td>
<td>the offset of <em class="parameter"><code>member</code></em> from the start of <em class="parameter"><code>struct_type</code></em>.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887731"></a><h3>
<a name="G-MEM-ALIGN:CAPS"></a>G_MEM_ALIGN</h3>
<a class="indexterm" name="id2887743"></a><pre class="programlisting">#define             G_MEM_ALIGN</pre>
<p>
Indicates the number of bytes to which memory will be aligned on the
current platform.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id2887760"></a><h3>
<a name="G-CONST-RETURN:CAPS"></a>G_CONST_RETURN</h3>
<a class="indexterm" name="id2887772"></a><pre class="programlisting">#define             G_CONST_RETURN</pre>
<p>
If <code class="literal">G_DISABLE_CONST_RETURNS</code> is defined, this macro expands to nothing.
By default, the macro expands to <code class="literal">const</code>. The macro 
should be used in place of <code class="literal">const</code> for functions that 
return a value that should not be modified. The purpose of this macro is 
to allow us to turn on <code class="literal">const</code> for returned constant 
strings by default, while allowing programmers who find that annoying to 
turn it off. This macro should only be used for return values and for
<span class="emphasis"><em>out</em></span> parameters, it doesn't make sense for 
<span class="emphasis"><em>in</em></span> parameters. 
</p>
</div>
</div>
<div class="refsect1" lang="en">
<a name="id2887835"></a><div class="refsect2" lang="en"><a name="id2887836"></a></div>
<hr>
<div class="refsect2" lang="en"><a name="id2887837"></a></div>
</div>
</div>
</body>
</html>
